; D:\PORNPOJ\Y2005\INC361\EX2010\MAX2MIN.C - Compiled by CC68K  Version 5.00 (c) 1991-2005  Peter J.Fondse
; #include<stdio.h>
; #define N 8
; int main()
; {
       section   code
       xdef      _main
_main:
       link      A6,#-72
       movem.l   D2/D3/D4/A2,-(A7)
       lea       -40(A6),A2
; int a[N] = {3, 21, 0, -3, 34, -14, 45, 18};
       lea       -72(A6),A0
       lea       main_a,A1
       moveq     #7,D0
main_1:
       move.l    (A1)+,(A0)+
       dbra      D0,main_1
; int b[N] = {0};
       move.l    A2,A0
       lea       main_b,A1
       moveq     #7,D0
main_2:
       move.l    (A1)+,(A0)+
       dbra      D0,main_2
; int  max, temp;
; int i,j,p;
; for( i=0;i<N;i++)
       clr.l     D2
main_3:
       cmp.l     #8,D2
       bge.s     main_5
; {
; b[i]=a[i];
       move.l    D2,D0
       lsl.l     #2,D0
       move.l    D2,D1
       lsl.l     #2,D1
       move.l    -72(A6,D0.L),0(A2,D1.L)
main_4:
       addq.l    #1,D2
       bra       main_3
main_5:
; }
; for(i=0;i<N-1;i++)
       clr.l     D2
main_6:
       cmp.l     #7,D2
       bge       main_8
; {
; max = b[i];
       move.l    D2,D0
       lsl.l     #2,D0
       move.l    0(A2,D0.L),D4
; for(j=i;j<N;j++)
       move.l    D2,D3
main_9:
       cmp.l     #8,D3
       bge.s     main_11
; {
; if(b[j] > max)
       move.l    D3,D0
       lsl.l     #2,D0
       cmp.l     0(A2,D0.L),D4
       bge.s     main_12
; {
; max = b[j];
       move.l    D3,D0
       lsl.l     #2,D0
       move.l    0(A2,D0.L),D4
; p = j;
       move.l    D3,-4(A6)
main_12:
       addq.l    #1,D3
       bra       main_9
main_11:
; }
; }
; temp = b[i];
       move.l    D2,D0
       lsl.l     #2,D0
       move.l    0(A2,D0.L),-8(A6)
; b[i] = max;
       move.l    D2,D0
       lsl.l     #2,D0
       move.l    D4,0(A2,D0.L)
; b[p] = temp;
       move.l    -4(A6),D0
       lsl.l     #2,D0
       move.l    -8(A6),0(A2,D0.L)
main_7:
       addq.l    #1,D2
       bra       main_6
main_8:
; }
; for( i=0;i<N;i++)
       clr.l     D2
main_14:
       cmp.l     #8,D2
       bge.s     main_16
; {
; printf(" %d  ", b[i]);
       move.l    D2,D1
       lsl.l     #2,D1
       move.l    0(A2,D1.L),-(A7)
       pea       @max2min_1
       bsr       _printf
       addq.w    #8,A7
main_15:
       addq.l    #1,D2
       bra       main_14
main_16:
; }
; printf(" \n\r");
       pea       @max2min_2
       bsr       _printf
       addq.w    #4,A7
; return 0;
       clr.l     D0
main_17:
       movem.l   (A7)+,D2/D3/D4/A2
       unlk      A6
       rts
; }
       section   data
main_a:
       dc.l      3,21,0,-3,34,-14,45,18
main_b:
       dc.l      0
       ds.b      28
@max2min_1:
       dc.b      32,37,100,32,32,0
@max2min_2:
       dc.b      32,10,13,0
       xref      _printf
